package greate.project;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.http.HttpMethods;
import org.apache.camel.impl.DefaultCamelContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @author v_zhangshun01
 */
public class HttpApp {

    public static void main(String[] args) throws Exception {

        // 创建默认上下文
        CamelContext context = new DefaultCamelContext();

        // 现开启想表达的是 ， camel 在开启后可以动态的新增和关闭路由。
        context.start();

        // 新增路由
        context.addRoutes(new HelloWorldRoute());

        synchronized (HttpApp.class) {
            HttpApp.class.wait();
        }
    }

    static class HelloWorldRoute extends RouteBuilder {

        String url = "https://tenapi.cn/qqzx/?qq=123456";

        @Override
        public void configure() {

            from("timer:foo?period=100000")
                    .setHeader(Exchange.HTTP_METHOD, HttpMethods.GET)
                    .to(url)
                    .process(exchange -> exchange.getMessage().setBody(exchange.getMessage().getBody()))
                    .log("${body}");

        }

    }

}
